<?php

/**
 * This is the model class for table "people".
 *
 * The followings are the available columns in table 'people':
 * @property integer $people_id
 * @property string $people_type
 * @property string $people_fname
 * @property string $people_lname
 * @property string $people_mname
 * @property string $people_gender
 * @property string $people_birthdate
 * @property string $people_marital_status
 * @property string $people_address_1
 * @property string $people_address_2
 * @property string $people_mobile
 * @property string $people_landline
 * @property string $people_email
 * @property string $people_photo
 *
 * The followings are the available model relations:
 * @property Alumni[] $alumnis
 * @property BatchHistory[] $batchHistories
 * @property User[] $users
 * @property Volunteer[] $volunteers
 */
class People extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return People the static model class
	 */
	public $uploadedFile;
	public function getPeopleType()
	{
		return array('volunteeer'=>'Volunteer','alumni'=>'Alumni');
	}
	public function getVolunteerName()
	{
		return $this->people_fname.' '.$this->people_mname.'. '.$this->people_lname;
	}

	public function getAlumniName()
	{
		return $this->people_fname.' '.$this->people_mname.'. '.$this->people_lname;
	}

	public function getGenderOptions(){
		return array('male'=>'Male','female'=>'Female');
	}

	public function getMaritalStatus(){
		return array('single'=>'Single','married'=>'Married','widowed'=>'Widowed','separated'=>'Separated','annuled'=>'Annuled');
	}

	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'people';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('people_type, people_fname, people_lname, people_mname, people_gender, people_birthdate, people_marital_status, people_address_1', 'required'),
			array('people_type', 'length', 'max'=>11),
			array('people_fname, people_lname, people_email, people_photo', 'length', 'max'=>45),
			array('people_mname', 'length', 'max'=>4),
			array('people_gender', 'length', 'max'=>7),
			array('people_marital_status, people_landline', 'length', 'max'=>10),
			array('people_address_1, people_address_2', 'length', 'max'=>255),
			array('people_mobile', 'length', 'max'=>15),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('people_id, people_type, people_fname, people_lname, people_mname, people_gender, people_birthdate, people_marital_status, people_address_1, people_address_2, people_mobile, people_landline, people_email, people_photo', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'alumnis' => array(self::HAS_MANY, 'Alumni', 'alumni_people_id'),
			'batchHistories' => array(self::HAS_MANY, 'BatchHistory', 'people_batch_id'),
			'users' => array(self::HAS_MANY, 'User', 'user_people_id'),
			'volunteers' => array(self::HAS_MANY, 'Volunteer', 'volunter_people_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'people_id' => 'People',
			'people_type' => 'Type',
			'people_fname' => 'First name',
			'people_lname' => 'Last name',
			'people_mname' => 'Middle Initial',
			'people_gender' => 'Sex',
			'people_birthdate' => ' Birthdate',
			'people_marital_status' => 'Marital Status',
			'people_address_1' => 'Address 1',
			'people_address_2' => 'Address 2',
			'people_mobile' => 'Mobile',
			'people_landline' => 'Landline',
			'people_email' => 'Email',
			'people_photo' => 'Photo',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('people_id',$this->people_id);
		$criteria->compare('people_type',$this->people_type,true);
		$criteria->compare('people_fname',$this->people_fname,true);
		$criteria->compare('people_lname',$this->people_lname,true);
		$criteria->compare('people_mname',$this->people_mname,true);
		$criteria->compare('people_gender',$this->people_gender,true);
		$criteria->compare('people_birthdate',$this->people_birthdate,true);
		$criteria->compare('people_marital_status',$this->people_marital_status,true);
		$criteria->compare('people_address_1',$this->people_address_1,true);
		$criteria->compare('people_address_2',$this->people_address_2,true);
		$criteria->compare('people_mobile',$this->people_mobile,true);
		$criteria->compare('people_landline',$this->people_landline,true);
		$criteria->compare('people_email',$this->people_email,true);
		$criteria->compare('people_photo',$this->people_photo,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}